package mortal.game.control
{
    import Message.Game.*;
    import com.mui.controls.*;
    import extend.flash.flower.*;
    import modules.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.info.*;
    import mortal.game.view.flowers.*;
    import mortal.game.view.system.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class FlowersController extends Controller
    {
        private var _flowersModule:FlowersModule;

        public function FlowersController()
        {
            
        }

        override protected function initView() : IView
        {
            if (!this._flowersModule)
            {
                this._flowersModule = new FlowersModule();
            }
            return this._flowersModule;
        }

        override protected function initServer() : void
        {
            Dispatcher.addEventListener(EventName.FlowerOpenHandselFlower, this.onOpenHandselFlowers);
            Dispatcher.addEventListener(EventName.FlowerHandselFlower, this.onFlowerHandselFlower);
            Dispatcher.addEventListener(EventName.FlowerKissBack, this.onFlowerKissBack);
            Dispatcher.addEventListener(EventName.FlowerUseInPack, this.onFlowerUseInPack);
            NetDispatcher.addCmdListener(ServerCommand.FlowersReceiveFlower, this.onReceiveFlower);
            NetDispatcher.addCmdListener(ServerCommand.FlowersWreathEffect, this.onWreathEffect);
            
        }

        private function onOpenHandselFlowers(event:DataEvent) : void
        {
            var _loc_2:String = null;
            if (event.data)
            {
                _loc_2 = event.data as String;
            }
            view.show();
            (view as FlowersModule).showHandselFlowerPanel();
            (view as FlowersModule).setDefaultName(_loc_2);
            
        }

        private function onFlowerHandselFlower(event:DataEvent) : void
        {
            var flowersData:FlowersData;
            var onClose:Function;
            var e:* = event;
            onClose = function (param1:int) : void
            {
                if (param1 == Alert.OK)
                {
                    GameProxy.flowers.handselFlower(flowersData.playerName, flowersData.isSign ? (EHandselFlowerType._EHandselFlowerTypeSign) : (EHandselFlowerType._EHandselFlowerTypeAnonymous), flowersData.propUid);
                    view.hide();
                }
                
            }
            ;
            flowersData = e.data as FlowersData;
            if (cache.friend.isFriend(flowersData.playerName))
            {
                GameProxy.flowers.handselFlower(flowersData.playerName, flowersData.isSign ? (EHandselFlowerType._EHandselFlowerTypeSign) : (EHandselFlowerType._EHandselFlowerTypeAnonymous), flowersData.propUid);
                view.hide();
            }
            else
            {
                Alert.show("       " + flowersData.playerName + "不是你的好友，赠送鲜花只会增加<font color=\'#00BEFF\'>魅力值</font>，<br>不会增加<font color=\'#FF00FF\'>亲密度</font>，是否继续赠送？", null, Alert.OK | Alert.CANCEL, null, onClose);
            }
            
        }

        private function onFlowerKissBack(event:DataEvent) : void
        {
            var _loc_2:* = event.data as String;
            GameProxy.flowers.flowerKissBack(_loc_2);
            
        }

        private function onFlowerUseInPack(event:DataEvent) : void
        {
            var _loc_2:* = event.data as ItemData;
            view.show();
            (view as FlowersModule).showHandselFlowerPanel();
            (view as FlowersModule).setSelectItem(_loc_2.effect);
            
        }

        private function onReceiveFlower(param1:SReceiveFlowerInfo) : void
        {
            if (param1.miniPlayer.name != cache.role.entityInfo.name)
            {
                view.show();
                (view as FlowersModule).showFlowerKissBackPanel(param1);
            }
            
        }

        private function onWreathEffect(param1:SFloatFlower) : void
        {
            if (SystemSetter.currentSetter.hideLightAndEffect)
            {
                
            }
            var _loc_2:* = param1.amount;
            var _loc_3:int = 10000;
            if (_loc_2 == 99)
            {
                _loc_3 = 10000;
            }
            else if (_loc_2 == 999)
            {
                _loc_3 = 15000;
            }
            FlowerManager.instance.addFlowerQueue(_loc_2, _loc_3);
            
        }

    }
}
